package leetcode.code0260;

public class Solution extends Solution260 {

	@Override
	public int[] singleNumber(int[] nums) {
		if (nums.length == 2)
			return nums;
		int xor = 0;
		for (int num : nums) {
			xor ^= num;
		}
		int divide = xor & (~xor + 1); // 分治特征
		int num1 = 0;
		int num2 = 0;
		for (int num : nums) {
			if ((num & divide) == 0) { // 按照最后1的位置是1或者是0分治
				num1 ^= num;
			} else {
				num2 ^= num;
			}
		}
		return new int[] { num1, num2 };
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
	}

}
